﻿using System;
using System.Windows.Forms;
using Business;
using Business.Entity.Vendas.MovimentacaoCaixa.SubClass.Sangria;
using Business.Forms;

namespace Vendas.Forms
{
    public partial class FormSangria : FormDefault
    {
        public FormSangria()
        {
            InitializeComponent();
            sangriaBindingSource.DataSource = new Sangria();
        }

        private void cmdSalvar_Click(object sender, EventArgs e)
        {
            Salvar();
        }

        private void Salvar()
        {
            var s = (Sangria)sangriaBindingSource.DataSource;
            Ecf.EcfHelper.GetEcf().Sangria(s.Valor, s.Historico);
            s.Usuario = Utils.UsuarioAtual;
            s.Caixa = Utils.Terminal.ConfiguracaoEcf.Caixa;
            SangriaRepository.Save(s);
            Close();
        }

        private void FormSangria_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyData)
            {
                case Keys.F5:
                    Salvar();
                    break;
                case Keys.Escape:
                    Close();
                    break;
            }
        }

        private void cmdCancelar_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}